create trigger for insert update delete sql server
create trigger for insert update delete sql server
Learn about create trigger for insert update delete sql server, we have the largest and most updated create trigger for insert update delete sql server information on alibabacloud.com
Classes;Update classes Set name = ' Five class ' WHERE name = ' Class 5 ';The update trigger saves the updated data in the deleted table after the data is updated, and the updated data is saved in the inserted table. # Update column-level triggers if (object_id (' Tgr_classes_update_column ', ' TR ') is not null)Drop
Example of a trigger codes:
Code of the insert, delete, and update trigger:
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->-- DBO. trgroups. SQL
If exists (
Select * From sysobj
Create trigger [updatetest] on [DBO]. [test]
For insert, update, delete
As
Begin
Declare
@ Isinsert bit,
@ Isupdate bit,
@ Isdelete bit
If exists (select 1 from inserted) and not exists (select 1 from deleted)
Set @ isinsert = 1
Else
Set @ isinsert = 0
If exists (select 1 f
SQL Server 2008 provides an enhanced SQL command merge for use in the msdn:http://msdn.microsoft.com/zh-cn/library/bb510625.aspx
Function: Inserts, updates, or deletes on the target table based on the results of joining with the source table. For example, you can synchronize two tables by inserting, updating, or deleting rows in a table based on differences foun
But sometimes, you can see the logic level, you can write the three triggers, just a little judgment.
You can determine whether a trigger is handled by inserting, deleting, or updating according to the following methods:
Copy Code code as follows:
--Declaring two variables
DECLARE @D BIT = 0
DECLARE @i BIT = 0
--If a record is found inside the deleted temporary touch, the old data is deleted
IF EXISTS (SELECT top 1 1 DELE
Label: 1. Introduction T-SQL (Transact structured Query Language) is the standard SQL extension that is the primary language for program and SQL Server communication. The T-SQL language consists mainly of the following parts:
Data definition Language (DDL): Used
portals are inserted. Deleting a portal from the index, including removing it from the clustered index, may delete the entry immediately. You may also create a ghost record to make the index entry a tombstone. Ghost exists only in the leaf layer. SQL Server will not delete
XML is added to SQL Server. the Modify () method is xml. modify (insert), xml. modify (delete), xml. modify (replace) corresponds to XML insert, delete, and modify operations.
The following XML is used as an example to describe th
The new Xml.modify () method is added to SQL Server, xml.modify (insert), xml.modify (delete), xml.modify (replace) to insert, delete, and modify the XML.
This article takes the following XML as an example to illustrate three type
XML is added to SQL Server. the Modify () method is xml. modify (insert), xml. modify (delete), xml. modify (replace) corresponds to XML insert, delete, and modify operations.
The following XML is used as an example to describe th
XML is added to SQL Server. the Modify () method is xml. modify (insert), xml. modify (delete), xml. modify (replace) corresponds to XML insert, delete, and modify operations.The following XML is used as an example to describe thr
meet the current conditionsSET @myDoc. Modify ('Insertif (count (/root/location/step) Then element step {"This is new step"}Else ()As first into (/root/location) [1] ')SELECT @myDoc;2. Update XML DECLARE @myDoc XML SET @myDoc = ' Laborhours= "1.1" Machinehours= ". 2" >manufacturing steps is described here. SELECT @myDoc; --The value of the LaborHours property in the replacement node location is SET @myDoc. Modify (' Replace value of (/roo
This article introduces mssqlserver to determine whether a trigger is processing an insert, delete, or update trigger. If you need to learn more, refer to.
This article introduces how to determine whether a trigger is processing a
Copy Code code as follows:
Create Trigger Tr_mastertable_update
On mastertable
After update
As
If update ([Type])--triggers this trigger when the Type field is updated
INSERT INTO masterlogtable
Select
Id
, (case [Typ
However, sometimes, you can view the logic of the process and write the three into a trigger, only to make a slight judgment.You can determine from the following method whether the trigger is triggered by processing the insert, delete, or update:Copy codeThe Code is as follows:-- Declare two variablesDECLARE @ d bit =
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.